home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: 12 Mar 1996 16:36:27 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4i4u9b$irt@solutions.solon.com>
- References: <4htonk$350@news.hklink.net> <AD69AACE9668D78B0@mcdiala09.it.luc.edu> <4i1kq3$2m0@solutions.solon.com> <AD6AFF6D9668E8DB7@mcdiala09.it.luc.edu>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <AD6AFF6D9668E8DB7@mcdiala09.it.luc.edu>,
- Verne Arase <VArase@varase.it.luc.edu> wrote:
- >In article <4i1kq3$2m0@solutions.solon.com>,
- >seebs@solutions.solon.com (Peter Seebach) wrote:
- > >>In this specific case, however, it _never_ hides an error. If malloc is
- > >>used in its standard context, we are simply coercing a slab of memory
- > >>aligned to the most stringent boundaries into a pointer of the desired
- > >>type.
-
- > >Which does *nothing*, because void pointers always convert to the desired
- > >type silently and automatically.
-
- >Provided you're not dealing with a pre-ANSI compiler.
-
- Of course; this is comp.lang.c, not comp.lang.c-and-its-predecessors.
-
- Unless explicitly described otherwise, code is assumed to be in C, not
- pre-ANSI C, GNU C, or whatever else.
-
- > >Further, it *did* hide an error in the specific case; <stdlib.h> was not
- > >included, and there was no prototype in scope.
-
- >Then that was what should have been said.
-
- It's better to give a newbie the most general and useful advice, which is to
- avoid casts unless you're ver clear on what they're doing in a given case.
-
- > >And you are _always_ redundant doing so, unless you're passing to a
- > >varaidic function or one with no prototype in scope.
-
- >I had a pre-ANSI compiler which defined malloc as returning char *.
-
- Cool. I have a pre-ANSI compiler which thinks sprintf() returns a char *
- too, and for that matter, I used to have one which thought that a[i] and i[a]
- were different.
-
- They're all broken.
-
- > >char is not a signed quantity. char is a quantity which may be signed or
- > >unsigned.
-
- >Every implementation I've seen makes char signed.
-
- And? Every implementation I've ever used has 32 bit longs. Shall we
- describe the C *language* as specifying that long is no more than 32 bits?
- Anyway, both of my Amiga C compilers have switches to select between signed
- and unsigned char at compile time.
-
- > >It's a question of usage. An unspecified short, int, or long is *always*
- > >signed, so it is clearly desireable for char to be signed. EOF is
- > >negative, and the getc family all return unsigned char or EOF, so it is
- > >clearly desireable for char to be unsigned.
-
- >While you'd probably want a short, int, or long to be signed, what's the
- >percentage of time you actually _want_ char to be signed? And what's the
- >percentage of time you gave a hoot whether you had a char * or an unsigned
- >char *?
-
- Well, in the cases where I care at all, I want char to be signed.
- If I want an unsigned char, I say unsigned. I like the consistency
- thing.
-
- >As for the getc routines: don't have any C references here, but don't they
- >return an int?
-
- Yes. An int which is (character converted to unsigned char) or EOF. In
- this context, it would be ideal if char were unsigned by default.
-
- > >If you don't put in casts, you will get warnings for any conversion not
- > >normally correct. This is helpful.
-
- >Depends on the compiler.
-
- >I've had IDEs where an uncasted pointer conversion just produced an error
- >and stopped the compile.
-
- If it was a legit conversion, the IDE was broken. If it wasn't, that's a good
- thing, a desireable behavior, and a feature.
-
- Of course, many things with IDE's are really C++ compilers, not C compilers; if
- you use the wrong compiler for a program, that's your own problem.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-